var currentPage=1;
var sortTypeId="";
var propertyTypeId="";
var allSort="";
var addTimeSort="";
var gPriceSort="";
var dPriceSort="";
var collectNumSort="";
var saleNumSort="";
var fenleiId="";
var shuxinId="";
var priceId="2";
var shangquanid="";

function qiugoujia(){
	if(uuuuid!=""){
		window.location.href="4.2.7qiugou_fabu.html";
	}else{
	   alert("未登录/或登录超时");
	   window.location.href="buy/12.0.0buy_wode.html";
	}
}

fenlei();

function fenlei(){
	$("#sortUl").html("");
     $.ajax({
			url: urlcore + "/api/sortType/Primaryclassification?coder=2",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				 var suns=0;
				 var sortUl="";
           	$.each(data.data.sortTypeList,function(i,n){
           		suns++;
           		 if(suns==1){
sortUl+='<li><a href="javascript:TwoclassificationFenlei2();">全部分类</a></li>'; 
				  }
 sortUl+='<li><a href="javascript:TwoclassificationFenlei('+n.id+');">'+n.sortName+'</a></li>'; 
           	});
           	$("#sortUl").append(sortUl);
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
		
}

function TwoclassificationFenlei(str){
	 	$("#sortSon").html("");
	    $.ajax({
			url: urlcore + "/api/sortType/TwoGoodsAlls?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	   if(data.data!=null){
           	   		$.each(data.data,function(g,h){
    var Fenleierji='<li id="'+h.id+'"><a href="javascript:selectChanPinByfenlei('+h.id+',\''+h.sortName+'\');">'+h.sortName+'</a></li>';
           			$("#sortSon").append(Fenleierji);
           	});
           	   }
           
           	
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}

function TwoclassificationFenlei2(){
	$("#area span").text("全部分类");
	fenleiId="";
	 $('#qiugou').html("");
	 currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}


function selectChanPinByfenlei(id,name){
	$("#area span").text(name);
	fenleiId=id;
	 $('#qiugou').html("");
	 currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

function selectChanPinByprice(id,name){
	$("#price span").text(name);
	priceId=id;
	 $('#qiugou').html("");
	 currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}



selectRemai();
var  ss=0;
function selectRemai(){
	//alert(priceId)
	//$("#chanping").html("");
	if(currentPage==1 || ss!=0 ||currentPage==2){
	$.ajax({ 
       url: urlcore +"/api/wantBuy/selectList?current="+currentPage+"&tradeAreaId="+shangquanid+"&sortTypeId="+fenleiId+"&sort="+priceId,
        type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				if(data.data.list!=null){
					ss=data.data.list.length;
		  $.each(data.data.list,function(y,n){
//		var zuotian=n.uptDatetime.pattern("hh:mm");
   var d1 = new Date(); 
  var d2 = new Date(Date.parse(n.uptDatetime));
  var dateds=1;
             if(parseInt((d1 - d2) / 60000)<60){
             	if(parseInt((d1 - d2) / 60000)<1){
             		 dateds=dateds+"分钟前更新";
             	}else{
             		 dateds=parseInt((d1 - d2) / 60000)+"分钟前更新";
             	}
             }else{
             if(parseInt((d1 - d2) / 60000)<2880){
             	     if(parseInt((d1 - d2) / 60000)<1300){
             	      dateds="今天"+d2.getHours()+":"+d2.getMinutes()+"更新"; //分+"小时前更新";
              }else{
var time=n.uptDatetime; 
var timearr=time.replace(" ",":").replace(/\:/g,"-").split("-"); 
var svns=0;
var zuotian="";
for(i=0;i<timearr.length;i++){
	svns++;
	/*if(svns==2){
     	zuotian+=timearr[i]+"-";
     }else if(svns==3){
     	zuotian+=timearr[i]+" ";
     }else */ if(svns==4){
     	zuotian+=timearr[i]+":";
     }else if(svns==5){
     	zuotian+=timearr[i];
     }
} 
             	   dateds="昨天"+zuotian+"更新";
             	     }
             }else{
var time=n.uptDatetime; 
var timearr=time.replace(" ",":").replace(/\:/g,"-").split("-"); 
var svns=0;
var genxin="";
for(i=0;i<timearr.length;i++){
	svns++;
	if(svns==2){
		genxin+=timearr[i]+"-";
	}else if(svns==3){
	 	genxin+=timearr[i]+" ";
	 }else if(svns==4){
     	genxin+=timearr[i]+":";
     }else if(svns==5){
     	genxin+=timearr[i];
     }
} 
             	dateds=genxin+"更新";
             }
              }
  
  
					var qiugou='<li>'+
			'<a href="4.2.9qiugou_detail.html?id='+n.id+'">';
			    if(n.status==1){  //求购成功
		qiugou+='<DIV style="position:absolute; top:0, left:0; width:400; height:300; z-index:0">'+
			'<img onerror="errorImg(this)" src="'+n.coverUrl+'"  width=400 height=300 />'+
		   '</DIV>'+
		   '<DIV style="position:absolute; top:20; left:190; width:200; height:100; text-align:center; z-index:2">'+
			'<IMG onerror="errorImg(this)" id=logo src="images/qiugouchenggong.png"  width=400 height=300">'+
		'</DIV>';
			    }else{
			    	qiugou+='<img onerror="errorImg(this)" src="'+n.coverUrl+'"/>';
			    }
				qiugou+='<h5>'+dateds+'</h5>'+
			'</a>'+
		    '</li>';
		    
				    $('#qiugou').append(qiugou);	
			 });
			 
			 
				}
			} else {
				if(data.msg != '空数据') {
					alert(data.msg)
				} else {
					$('#thiscount').text(0);
				}
			}

		},
		error: function() {
			alert("error");
		}
	});
	}
	 
	 
}



//商圈
 function shangquan(){
    	 $.ajax({
             url: urlcore + "/api/tradeArea/selectList",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
				//	alert(JSON.stringify(data.data));
				var suns=0;
				var shangquan="";
					  $.each(data.data,function(y,n){
					  	suns++;
					  	if(suns==1){
				 shangquan+='<li  onclick="selsetshangquan2()">全部商圈</li> ';
                
					  	}
 shangquan+='<li  onclick="selsetshangquan('+n.id+',\''+n.areaName+'\')">'+n.areaName+'</li> ';
                    	
					  });
					    $("#shangquan").append(shangquan);					  
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	
    }
 
 
 function selsetshangquan(id,name){
 
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html(name);
	shangquanid=id;
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
 $('#qiugou').html("");
selectRemai();
 	
 	
 }
 
 

 function selsetshangquan2(){
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html("全部商圈");
	shangquanid="";
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
 $('#qiugou').html("");
selectRemai();
 }
 
